﻿using System.Collections.Generic;
using System.Xml.Serialization;

namespace XuanFe.AppLaunch.Config
{
    /// <summary>
    /// 日志配置类
    /// </summary>
    [XmlRootAttribute(ElementName = "log4net")]
    public class LogConfiguration
    {
        public LogConfiguration()
        {
            this.Appenders = new List<AppenderItem>();
            this.Root = new RootItem();
            this.Loggers = new List<LoggerItem>();
        }

        [XmlElementAttribute(ElementName = "appender")]
        public List<AppenderItem> Appenders { get; set; }
        [XmlElementAttribute(ElementName = "root")]
        public RootItem Root { get; set; }
        [XmlElementAttribute(ElementName = "logger")]
        public List<LoggerItem> Loggers { get; set; }

        public class RootItem
        {
            public RootItem()
            {
                this.Level = new ValueItem() { Value = "ALL" };
                this.AppenderRefs = new List<AppenderRefItem>();
            }

            [XmlElementAttribute(ElementName = "level")]
            public ValueItem Level { get; set; }
            [XmlElementAttribute(ElementName = "appender-ref")]
            public List<AppenderRefItem> AppenderRefs { get; set; }
        }
        public class LoggerItem
        {
            public LoggerItem()
            {
                this.Level = new ValueItem() { Value = "ALL" };
                this.AppenderRefs = new List<AppenderRefItem>();
            }

            [XmlAttributeAttribute(AttributeName = "name")]
            public string Name { get; set; }
            [XmlAttributeAttribute(AttributeName = "additivity")]
            public string Additivity { get; set; }
            [XmlElementAttribute(ElementName = "level")]
            public ValueItem Level { get; set; }
            [XmlElementAttribute(ElementName = "appender-ref")]
            public List<AppenderRefItem> AppenderRefs { get; set; }
        }
        public class AppenderRefItem
        {
            private string appenderRef;

            [XmlAttributeAttribute(AttributeName = "ref")]
            public string Ref
            {
                get { return this.appenderRef; }
                set { this.appenderRef = value; }
            }
        }
        public class AppenderItem
        {
            public AppenderItem()
            {
                this.Filters = new List<FilterNode>();
                this.File = new ValueItem();
                this.AppendToFile = new ValueItem();
                this.LockingModel = new ValueItem();
                this.RollingStyle = new ValueItem();
                this.DatePattern = new ValueItem();
                this.StaticLogFileName = new ValueItem();
                this.MaxSizeRollBackups = new ValueItem();
                this.MaximumFileSize = new ValueItem();
                this.Layout = new LayoutNode();
            }

            [XmlAttributeAttribute(AttributeName = "name")]
            public string Name { get; set; }
            [XmlAttributeAttribute(AttributeName = "type")]
            public string Type { get; set; }
            [XmlElementAttribute(ElementName = "filter")]
            public List<FilterNode> Filters { get; set; }
            [XmlElementAttribute(ElementName = "file")]
            public ValueItem File { get; set; }
            [XmlElementAttribute(ElementName = "appendToFile")]
            public ValueItem AppendToFile { get; set; }
            [XmlElementAttribute(ElementName = "lockingModel")]
            public ValueItem LockingModel { get; set; }
            [XmlElementAttribute(ElementName = "rollingStyle")]
            public ValueItem RollingStyle { get; set; }
            [XmlElementAttribute(ElementName = "datePattern")]
            public ValueItem DatePattern { get; set; }
            [XmlElementAttribute(ElementName = "staticLogFileName")]
            public ValueItem StaticLogFileName { get; set; }
            [XmlElementAttribute(ElementName = "maxSizeRollBackups")]
            public ValueItem MaxSizeRollBackups { get; set; }
            [XmlElementAttribute(ElementName = "maximumFileSize")]
            public ValueItem MaximumFileSize { get; set; }
            [XmlElementAttribute(ElementName = "layout")]
            public LayoutNode Layout { get; set; }
        }
        public class LayoutNode
        {
            public LayoutNode()
            {
                this.ConversionPattern = new ValueItem();
            }

            [XmlAttributeAttribute(AttributeName = "type")]
            public string Type { get; set; }
            [XmlElementAttribute(ElementName = "conversionPattern")]
            public ValueItem ConversionPattern { get; set; }
        }
        public class FilterNode
        {
            [XmlAttributeAttribute(AttributeName = "type")]
            public string Type { get; set; }
            [XmlElementAttribute(ElementName = "levelToMatch")]
            public ValueItem LevelToMatch { get; set; }
        }
        public class ValueItem
        {
            [XmlAttributeAttribute(AttributeName = "value")]
            public string Value { get; set; }
            [XmlAttributeAttribute(AttributeName = "type")]
            public string Type { get; set; }
        }
    }
}
